//
//  STMainViewController.swift
//  STVVeibo
//
//  Created by leergou on 16/7/19.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

import UIKit

class STMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 撰写按钮跳转
        let tabBar = STTabBar()
        tabBar.closure = {
            
            let composeView = STComposeView()
            composeView.composeViewShow(self)
            
//            self.presentViewController(UINavigationController(rootViewController: STComposeController()), animated: true, completion: nil)
            
        }
        
        setValue(tabBar, forKey: "tabBar")

        addChildViewController(STHomeViewController(), title: "首页", imgName: "tabbar_home")
        
        addChildViewController(STMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        
        addChildViewController(STDiscoverViewController(), title: "发现", imgName: "tabbar_message_center")
        
        addChildViewController(STProfileViewController(), title: "我", imgName: "tabbar_profile")
    }
    
    // 自定义方法,添加子控制器
    func addChildViewController(vc: UIViewController, title: String, imgName: String) {
        
        vc.title = title
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: ("\(imgName)_selected"))?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 设置字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:ThemeColor], forState: .Selected)
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }

}
